Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Promise overload type to functions #221

Closed
wants to merge 9 commits into from

Conversation

jpmonette
Copy link
Contributor

@jpmonette jpmonette commented Feb 17, 2021

Resolves #196

  • Backward compatible
  • Simply remove successCB and errorCB from the existing functions to return Promise
  • Deprecating need for promiser and promiserNoRejection

Example:

before

import { query } from "./react.force.net";
import { promiser } from "./react.force.util";

type Accounts = Array<{ Id: string }>;

// before sync
query<Accounts>(
  "SELECT Id FROM Account",
  (accounts) => console.log(accounts),
  (err) => console.error(err),
);

// before async
const queryAsync = promiser(query);

queryAsync("SELECT Id FROM Account") // typing has been stripped :(
  .then((accounts: Accounts) => console.log(accounts))
  .catch((err) => console.error(err));

after

import { query } from "./react.force.net";

type Accounts = Array<{ Id: string }>;

// after sync (no change)
query<Accounts>(
  "SELECT Id FROM Account",
  (accounts) => console.log(accounts),
  (err) => console.error(err),
);

// after async
query<Accounts>("SELECT Id FROM Account") // typing works! 🚀
  .then((accounts) => console.log(accounts))
  .catch((err) => console.error(err));

try {
  const accounts = await query<Accounts>("SELECT Id FROM Account"); // typing works! 🚀
  console.log(accounts);
} catch (e) {
  console.error(e);
}

@jpmonette jpmonette changed the title Add Promise overload type to functions Adding Promise overload type to functions Feb 17, 2021
@jpmonette
Copy link
Contributor Author

@wmathurin As discussed in #196, here's the PR introducing typed promises for each functions. This is pretty close to "done", so would be keen to hear any suggestion.

@wmathurin
Copy link
Contributor

Closing PR - maybe one day we will add support for promise overloads.

@wmathurin wmathurin closed this Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better support for promises
2 participants